package com.ecommerce.product.dto;

import com.ecommerce.product.entity.Product;
import org.mapstruct.Mapper;
// 移除未使用的 import org.mapstruct.Mapping
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 产品MapStruct映射接口
 */
@Mapper(componentModel = "spring")
public interface ProductMapper {

    /**
     * 映射器实例
     */
    ProductMapper INSTANCE = Mappers.getMapper(ProductMapper.class);

    /**
 * 实体转响应DTO
 * @param product 产品实体
 * @return 产品响应DTO
 */
    @org.mapstruct.Mapping(target = "id", source = "id")
    @org.mapstruct.Mapping(target = "name", source = "name")
    @org.mapstruct.Mapping(target = "description", source = "description")
    @org.mapstruct.Mapping(target = "price", source = "price")
    @org.mapstruct.Mapping(target = "stock", source = "stock")
    @org.mapstruct.Mapping(target = "createdAt", source = "createdAt")
    @org.mapstruct.Mapping(target = "updatedAt", source = "updatedAt")
    @org.mapstruct.Mapping(target = "categoryId", source = "categoryId")
    @org.mapstruct.Mapping(target = "imageUrl", source = "imageUrl")
    @org.mapstruct.Mapping(target = "sales", source = "sales")
    ProductResponse entityToResponseDto(Product product);

    /**
 * 实体列表转响应DTO列表
 * @param products 产品实体列表
 * @return 产品响应DTO列表
 */
    @org.mapstruct.Mapping(target = "id", source = "id")
    @org.mapstruct.Mapping(target = "createdAt", source = "createdAt")
    @org.mapstruct.Mapping(target = "updatedAt", source = "updatedAt")
    @org.mapstruct.Mapping(target = "categoryId", source = "categoryId")
    @org.mapstruct.Mapping(target = "imageUrl", source = "imageUrl")
    @org.mapstruct.Mapping(target = "sales", source = "sales")
    List<ProductResponse> entityToResponseDtoList(List<Product> products);

    /**
     * 创建请求转实体
     * @param createRequest 创建请求
     * @return 产品实体
     */
    Product createRequestToEntity(ProductCreateRequest createRequest);

    /**
     * 更新实体
     * @param updateRequest 更新请求
     * @param product 产品实体
     */
    void updateEntity(@MappingTarget Product product, ProductUpdateRequest updateRequest);
}